import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import time, subprocess
from protocol.decorators import edp_service, instant, instant_req
class mock:
    @staticmethod
    def launch_dlc_internal():
        import tkinter as tk
        root = tk.Tk()
        root.title("DeepLabCut GUI")
        root.geometry("800x600")
        label = tk.Label(root, text="DeepLabCut GUI 模拟界面")
        label.pack(pady=20)
        button = tk.Button(root, text="关闭", command=root.destroy)
        button.pack(pady=10)
        root.mainloop()

# import deeplabcut
dlc = mock
@edp_service
class DLCGUI:
    name = 'deeplabcut-gui'
    desc = 'local GUI for deeplabcut'
    category = 'tracking'
    tasks = [
        'main: FilePath -> Map<Str, List<List<(PointF, Float)>>>',
        'gui: Void -> Void',
        'test: Void -> Void'
    ]

    def run_task(self):
        dlc.launch_dlc_internal()

    def main(self):
        return self.run_task()
    
    def gui(self):
        process = subprocess.Popen(['python', '-m', 'deeplabcut'])
        # wait for process to finish
        process.wait()
        print('process.returncode:', process.returncode)

    def test(self):
        time.sleep(10)
        return None

if __name__ == '__main__':
    DLCGUI.app.run(host='127.0.0.1', port=10000, debug=True)
